Skip to content

Commit

Permalink
test: Add unit tests for Revive linter in main_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaredevelop committed Aug 13, 2024
1 parent 7371d82 commit ff9b561
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions revive/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package main_test

import (
"context"
"flag"
"os"
"testing"

"dagger.io/dagger"
"github.com/stretchr/testify/require"
)

var c *dagger.Client

func TestMain(m *testing.M) {
flag.Parse()

ctx := context.Background()

c, _ = dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
defer c.Close()

code := m.Run()
defer c.Close()
os.Exit(code)
}

func Test_Revive(t *testing.T) {
t.Parallel()
ctx := context.Background()

t.Run("Test_revive_check", func(t *testing.T) {
t.Parallel()
container := base()
require.NotNil(t, container)

_, err := container.
WithMountedDirectory("/go", c.Host().Directory("./test/testdata/")).
WithWorkdir("/go").
WithExec([]string{"revive", "-set_exit_status", "./..."}).
Stdout(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), "don't use underscores in Go names")
})
t.Run("Test_revive_version", func(t *testing.T) {
t.Parallel()
container := base()
require.NotNil(t, container)

out, err := container.
WithExec([]string{"revive", "-version"}).
Stdout(ctx)
require.NoError(t, err)
require.Contains(t, out, "version")
})
}

func base() *dagger.Container {
image := c.Container().
From("ghcr.io/mgechev/revive:latest")

return c.Container().
From("golang:alpine").
WithFile("/usr/bin/revive", image.File("/usr/bin/revive"))
}

0 comments on commit ff9b561

Please sign in to comment.