github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/helper/structure/suppress_json_diff_test.go (about)

     1  package structure
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestSuppressJsonDiff_same(t *testing.T) {
     8  	original := `{ "enabled": true }`
     9  	new := `{ "enabled": true }`
    10  	expected := true
    11  
    12  	actual := SuppressJsonDiff("test", original, new, nil)
    13  	if actual != expected {
    14  		t.Fatal("[ERROR] Identical JSON values shouldn't cause a diff")
    15  	}
    16  }
    17  
    18  func TestSuppressJsonDiff_sameWithWhitespace(t *testing.T) {
    19  	original := `{
    20  	  "enabled": true
    21  	}`
    22  	new := `{ "enabled": true }`
    23  	expected := true
    24  
    25  	actual := SuppressJsonDiff("test", original, new, nil)
    26  	if actual != expected {
    27  		t.Fatal("[ERROR] Identical JSON values shouldn't cause a diff")
    28  	}
    29  }
    30  
    31  func TestSuppressJsonDiff_differentValue(t *testing.T) {
    32  	original := `{ "enabled": true }`
    33  	new := `{ "enabled": false }`
    34  	expected := false
    35  
    36  	actual := SuppressJsonDiff("test", original, new, nil)
    37  	if actual != expected {
    38  		t.Fatal("[ERROR] Different JSON values should cause a diff")
    39  	}
    40  }
    41  
    42  func TestSuppressJsonDiff_newValue(t *testing.T) {
    43  	original := `{ "enabled": true }`
    44  	new := `{ "enabled": false, "world": "round" }`
    45  	expected := false
    46  
    47  	actual := SuppressJsonDiff("test", original, new, nil)
    48  	if actual != expected {
    49  		t.Fatal("[ERROR] Different JSON values should cause a diff")
    50  	}
    51  }