github.com/leg100/ots@v0.0.7-0.20210919080622-034055ced4bd/plan_file_test.go (about)

     1  package ots
     2  
     3  import (
     4  	"encoding/json"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestPlanFile(t *testing.T) {
    13  	data, err := os.ReadFile("testdata/plan.json")
    14  	require.NoError(t, err)
    15  
    16  	file := PlanFile{}
    17  	require.NoError(t, json.Unmarshal(data, &file))
    18  
    19  	want := PlanFile{
    20  		ResourcesChanges: []ResourceChange{
    21  			{
    22  				Change: Change{
    23  					Actions: []ChangeAction{
    24  						CreateAction,
    25  					},
    26  				},
    27  			},
    28  			{
    29  				Change: Change{
    30  					Actions: []ChangeAction{
    31  						CreateAction,
    32  					},
    33  				},
    34  			},
    35  		},
    36  	}
    37  	assert.Equal(t, want, file)
    38  }
    39  
    40  func TestPlanFile_Changes(t *testing.T) {
    41  	data, err := os.ReadFile("testdata/plan.json")
    42  	require.NoError(t, err)
    43  
    44  	file := PlanFile{}
    45  	require.NoError(t, json.Unmarshal(data, &file))
    46  
    47  	adds, updates, deletes := file.Changes()
    48  
    49  	assert.Equal(t, 2, adds)
    50  	assert.Equal(t, 0, updates)
    51  	assert.Equal(t, 0, deletes)
    52  }