Skip to content

Commit

Permalink
lint: Add linter to CI, fix existing lint issues
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Kyrouac <[email protected]>
  • Loading branch information
ckyrouac committed May 22, 2024
1 parent c7ee261 commit aa3f1e9
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ jobs:
make GOOPTS=-buildvcs=false
export PATH=$PATH:$HOME/go/bin
make integration_tests
- name: lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.58.2
export PATH=$PATH:$HOME/go/bin
make lint
- name: gofmt
run: |
test -z $(gofmt -l .)
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ all: out_dir
out_dir:
mkdir -p $(output_dir)

lint:
golangci-lint --build-tags $(build_tags) run

integration_tests:
ginkgo run -tags $(build_tags) --skip-package test ./...

Expand Down
5 changes: 4 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ func doRun(flags *cobra.Command, args []string) error {
var vmConsoleWg sync.WaitGroup
vmConsoleWg.Add(1)
go func() {
bootcVM.PrintConsole()
err := bootcVM.PrintConsole()
if err != nil {
logrus.Errorf("error printing VM console: %v", err)
}
}()

err = bootcVM.WaitForSSHToBeReady()
Expand Down
3 changes: 0 additions & 3 deletions pkg/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,9 @@ type BootcVMCommon struct {
cmd []string
pidFile string
imageID string
imageDigest string
noCredentials bool
hasCloudInit bool
cloudInitDir string
cloudInitArgs string
bootcDisk bootc.BootcDisk
cacheDirLock utils.CacheLock
}

Expand Down
6 changes: 1 addition & 5 deletions pkg/vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func deleteAllVMs() {

var flags libvirt.ConnectListAllDomainsFlags
domains, err := conn.ListAllDomains(flags)
Expect(err).To(Not(HaveOccurred()))
for _, domain := range domains {
err = domain.Destroy()
Expect(err).To(Not(HaveOccurred()))
Expand All @@ -140,11 +141,6 @@ func deleteAllVMs() {
}
}

func deleteCache() {
err := os.RemoveAll(testUser.CacheDir())
Expect(err).To(Not(HaveOccurred()))
}

var _ = Describe("VM", func() {
AfterEach(func() {
deleteAllVMs()
Expand Down
16 changes: 12 additions & 4 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ var _ = Describe("E2E", func() {
imagesListOutput, _, err := e2e.RunPodman("images", e2e.BaseImage, "--format", "json")
Expect(err).To(Not(HaveOccurred()))
imagesList := []map[string]interface{}{}
json.Unmarshal([]byte(imagesListOutput), &imagesList)
err = json.Unmarshal([]byte(imagesListOutput), &imagesList)
Expect(err).To(Not(HaveOccurred()))
Expect(imagesList).To(HaveLen(1))
})

Expand All @@ -78,7 +79,8 @@ var _ = Describe("E2E", func() {

It("should start an ssh session into the VM", func() {
// Send a command to the VM and check the output
vm.SendCommand("echo 'hello'", "hello")
err := vm.SendCommand("echo 'hello'", "hello")
Expect(err).To(Not(HaveOccurred()))
Expect(vm.StdOut[len(vm.StdOut)-1]).To(ContainSubstring("hello"))
})

Expand Down Expand Up @@ -165,7 +167,10 @@ var _ = Describe("E2E", func() {

AfterAll(func() {
vm.StdIn.Close()
e2e.Cleanup()
err := e2e.Cleanup()
if err != nil {
Fail(err.Error())
}
})
})

Expand Down Expand Up @@ -304,7 +309,10 @@ var _ = Describe("E2E", func() {
activeVM.StdIn.Close()
inactiveVM.StdIn.Close()
stoppedVM.StdIn.Close()
e2e.Cleanup()
err := e2e.Cleanup()
if err != nil {
Fail(err.Error())
}
})
})
})
5 changes: 4 additions & 1 deletion test/e2e/test_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func (w *TestVM) WaitForBoot() (err error) {

// SendCommand sends a command to the VM's stdin and waits for the output
func (w *TestVM) SendCommand(cmd string, output string) (err error) {
w.StdIn.Write([]byte(cmd + "\n"))
_, err = w.StdIn.Write([]byte(cmd + "\n"))
if err != nil {
return fmt.Errorf("unable to write to VM stdin: %w", err)
}

timeout := 2 * time.Minute
interval := 1 * time.Second
Expand Down

0 comments on commit aa3f1e9

Please sign in to comment.