diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c19ea78..e128627 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -58,12 +58,10 @@ jobs: - name: Build pv-mounter run: | - go build -o pv-mounter ./cmd/plugin/main.go - ls -al - pwd + make bin - name: Create mountpoint - run: mkdir /home/runner/work/pv-mounter/pv-mounter/foo + run: mkdir foo - name: Check PVC status run: | @@ -77,9 +75,14 @@ jobs: # run: kubectl wait --for=condition=Bound pvc/test-pvc --timeout=2m - name: Run tests - env: - KUBECONFIG: ${{ secrets.KUBECONFIG }} - run: go test -v ./pkg/plugin + run: | + ./bin/pv-mounter mount default test-pvc foo + touch foo/dupa + ls -l foo/dupa + ./bin/pv-mounter clean default test-pvc foo +# env: +# KUBECONFIG: ${{ secrets.KUBECONFIG }} +# run: go test -v ./pkg/plugin - name: Delete pod and PVC run: | diff --git a/pkg/plugin/mount_test.go b/pkg/plugin/mount_test.go deleted file mode 100644 index c62a6f6..0000000 --- a/pkg/plugin/mount_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package plugin - -import ( - "fmt" - "io/ioutil" - "os/exec" - "path/filepath" - "testing" -) - -func runCommand(cmdStr string) error { - cmd := exec.Command("sh", "-c", cmdStr) - output, err := cmd.CombinedOutput() - if err != nil { - return fmt.Errorf("command '%s' failed with error: %v and output: %s", cmdStr, err, string(output)) - } - return nil -} - -func TestMountPVC(t *testing.T) { - namespace := "default" - pvcName := "test-pvc" - localMountPoint := "/home/runner/work/pv-mounter/pv-mounter/foo" - - // Run the mount command using the tool - mountCmd := fmt.Sprintf("/home/runner/work/pv-mounter/pv-mounter/pv-mounter mount %s %s %s", namespace, pvcName, localMountPoint) - if err := runCommand(mountCmd); err != nil { - t.Fatalf("Failed to mount PVC: %v", err) - } - - // Verify that the filesystem is writable - testFilePath := filepath.Join(localMountPoint, "testfile.txt") - testData := []byte("This is a test file.") - err := ioutil.WriteFile(testFilePath, testData, 0644) - if err != nil { - t.Fatalf("Failed to write to the mounted filesystem: %v", err) - } - - // Verify that the file was written correctly - readData, err := ioutil.ReadFile(testFilePath) - if err != nil { - t.Fatalf("Failed to read the test file from the mounted filesystem: %v", err) - } - if string(readData) != string(testData) { - t.Fatalf("Data read from the test file does not match expected data: got %s, want %s", string(readData), string(testData)) - } - - // Run the unmount command using the tool - unmountCmd := fmt.Sprintf("/home/runner/work/pv-mounter/pv-mounter/pv-mounter clean %s", localMountPoint) - if err := runCommand(unmountCmd); err != nil { - t.Fatalf("Failed to unmount the PVC: %v", err) - } -}