Skip to content

Commit

Permalink
test: add alias test (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny0826 committed Sep 8, 2022
1 parent 1a448cc commit ec3c65e
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions cmd/alias_test.go
@@ -0,0 +1,81 @@
package cmd

import (
"io/ioutil"
"os"
"testing"
)

func Test_updateFile(t *testing.T) {
testFile, _ := ioutil.TempFile("", "")
defer os.Remove(testFile.Name())
type args struct {
cxt string
path string
}
tests := []struct {
name string
args args
wantErr bool
}{
// TODO: Add test cases.
{
name: "test",
args: args{
cxt: "test",
path: testFile.Name(),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := updateFile(tt.args.cxt, tt.args.path); (err != nil) != tt.wantErr {
t.Errorf("updateFile() error = %v, wantErr %v", err, tt.wantErr)
}
file, err := os.ReadFile(tt.args.path)
if err != nil {
t.Errorf("updateFile() error = %v, wantErr %v", err, tt.wantErr)
}
if string(file) != tt.args.cxt {
t.Errorf("updateFile() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func Test_writeAppend(t *testing.T) {
bashFile, _ := ioutil.TempFile("", ".bash")
defer os.Remove(bashFile.Name())
type args struct {
context string
path string
}
tests := []struct {
name string
args args
wantErr bool
}{
// TODO: Add test cases.
{
name: "test",
args: args{
context: "test",
path: bashFile.Name(),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := writeAppend(tt.args.context, tt.args.path); (err != nil) != tt.wantErr {
t.Errorf("writeAppend() error = %v, wantErr %v", err, tt.wantErr)
}
file, err := os.ReadFile(tt.args.path)
if err != nil {
t.Errorf("writeAppend() error = %v, wantErr %v", err, tt.wantErr)
}
if string(file) != tt.args.context+"\n" {
t.Errorf("writeAppend() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

0 comments on commit ec3c65e

Please sign in to comment.