Skip to content

Commit

Permalink
refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
aq17 committed Apr 14, 2023
1 parent 8027a91 commit 4204031
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions upgrade/migrations_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package upgrade

import (
"go/parser"
"go/token"
"ioutil"
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -56,29 +55,25 @@ func Provider() tfbridge.ProviderInfo {
`

// Write original program to temporary file
orig, err := os.Create("original.go")
tmpDir := t.TempDir()
origPath := filepath.Join(tmpDir, "original.go")
orig, err := os.Create(origPath)
assert.Nil(t, err)
defer os.Remove("original.go")
_, err = orig.Write([]byte(origProgram))
assert.Nil(t, err)

// Parse to ast
fs := token.NewFileSet()
f, err := parser.ParseFile(fs, "original.go", nil, parser.DeclarationErrors|parser.ParseComments)
assert.Nil(t, err)

// Perform auto aliasing migration
_, err = AutoAliasingMigration(fs, f, "original.go", "test")
err = AutoAliasingMigration(origPath, "test")
assert.Nil(t, err)

newProgram, err := ioutil.ReadFile("original.go")
newProgram, err := ioutil.ReadFile(origPath)
assert.Nil(t, err)

expectedProgram := `package test
import (
"fmt"
// embed package blank import
// embed is used to store bridge-metadata.json in the compiled binary
_ "embed"
"path/filepath"
"strings"
Expand Down Expand Up @@ -127,6 +122,6 @@ func Provider() tfbridge.ProviderInfo {
var metadata []byte
`
// Compare against expected program
assert.Equal(t, newProgram, []byte(expectedProgram))
assert.Equal(t, string(newProgram), expectedProgram)

}

0 comments on commit 4204031

Please sign in to comment.