github.com/mpchadwick/dbanon@v0.7.1/integration/dbanon_test.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  	"os/exec"
     6  	"path"
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  var binaryName = "dbanon"
    12  
    13  var version string
    14  
    15  func TestDbanon(t *testing.T) {
    16  	os.Chdir("..")
    17  	dir, _ := os.Getwd()
    18  
    19  	cmd1 := exec.Command(path.Join(dir, binaryName))
    20  	out1, _ := cmd1.CombinedOutput()
    21  	res1 := strings.TrimSpace(string(out1))
    22  	if res1 != "You must specify a config" {
    23  		t.Errorf("Got %s expected missing config error", res1)
    24  	}
    25  
    26  	versCmd := exec.Command("git", "describe", "--tags")
    27  	versOut, _ := versCmd.CombinedOutput()
    28  	versRes := strings.TrimSpace(string(versOut))
    29  
    30  	cmd2 := exec.Command(path.Join(dir, binaryName), "-version")
    31  	out2, _ := cmd2.CombinedOutput()
    32  	res2 := strings.TrimSpace(string(out2))
    33  	if res2 != versRes {
    34  		t.Errorf("Got %s expected %s", res2, versRes)
    35  	}
    36  
    37  	cmdStr3 := "cat integration/magento_raw.sql | ./dbanon -config=magento2"
    38  	cmd3 := exec.Command("bash", "-c", cmdStr3)
    39  	out3, _ := cmd3.CombinedOutput()
    40  	res3 := strings.TrimSpace(string(out3))
    41  	if strings.Contains(res3, "adminFirstName") {
    42  		t.Error("Expected no adminFirstName")
    43  	}
    44  	if strings.Contains(res3, "customer1FirstName") {
    45  		t.Error("Expected no customer1FirstName")
    46  	}
    47  	if strings.Contains(res3, "customer2LastName") {
    48  		t.Error("Expected no customer2LastName")
    49  	}
    50  
    51  	cmdStr4 := "cat integration/magento_eav_before.sql | ./dbanon -config=magento2 map-eav"
    52  	cmd4 := exec.Command("bash", "-c", cmdStr4)
    53  	out4, _ := cmd4.CombinedOutput()
    54  	res4 := strings.TrimSpace(string(out4))
    55  	if !strings.Contains(res4, "\"5\": firstname") {
    56  		t.Errorf("First name not processed correctly")
    57  	}
    58  
    59  	if !strings.Contains(res4, "\"28\": street") {
    60  		t.Errorf("Street not processed correctly")
    61  	}
    62  
    63  	cmdStr5 := "cat integration/laravel.sql | ./dbanon -config=integration/laravel.yml"
    64  	cmd5 := exec.Command("bash", "-c", cmdStr5)
    65  	out5, _ := cmd5.CombinedOutput()
    66  	res5 := strings.TrimSpace(string(out5))
    67  	if strings.Contains(res5, "Bob Smith") {
    68  		t.Error("Expected no Bob Smith")
    69  	}
    70  }