2018-03-10 19:08:31 +01:00
|
|
|
package configupgrade
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2019-09-10 00:58:44 +02:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
2018-03-10 19:08:31 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMaybeAlreadyUpgraded(t *testing.T) {
|
|
|
|
t.Run("already upgraded", func(t *testing.T) {
|
2019-06-30 09:38:36 +02:00
|
|
|
sources, err := LoadModule("testdata/already-upgraded")
|
2018-03-10 19:08:31 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
got, rng := sources.MaybeAlreadyUpgraded()
|
|
|
|
if !got {
|
|
|
|
t.Fatal("result is false, but want true")
|
|
|
|
}
|
|
|
|
gotRange := rng.ToHCL()
|
|
|
|
wantRange := hcl.Range{
|
|
|
|
Filename: "versions.tf",
|
|
|
|
Start: hcl.Pos{Line: 3, Column: 3, Byte: 15},
|
|
|
|
End: hcl.Pos{Line: 3, Column: 33, Byte: 45},
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(gotRange, wantRange) {
|
|
|
|
t.Errorf("wrong range\ngot: %#v\nwant: %#v", gotRange, wantRange)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("not yet upgraded", func(t *testing.T) {
|
2019-06-30 09:38:36 +02:00
|
|
|
sources, err := LoadModule("testdata/valid/noop/input")
|
2018-03-10 19:08:31 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
got, _ := sources.MaybeAlreadyUpgraded()
|
|
|
|
if got {
|
|
|
|
t.Fatal("result is true, but want false")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|