blob: 318403d5574d873abb5bf09817d9437a84c8a68f [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package main
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestNewFileEdit(t *testing.T) {
t.Parallel()
var tests = []struct {
input string
expected *fileEdit
expectedErr bool
}{
{
input: "path/to/file:test-contents",
expected: &fileEdit{
filepath: "path/to/file",
contents: "test-contents",
},
expectedErr: false,
},
{
input: "invalid-input",
expected: nil,
expectedErr: true,
},
}
for _, test := range tests {
edit, err := newFileEdit(test.input)
if err == nil {
if test.expectedErr {
t.Errorf("expected error, got nil")
}
} else if !test.expectedErr {
t.Errorf("got unexpected err %v", err)
}
if diff := cmp.Diff(test.expected, edit, cmp.AllowUnexported(fileEdit{})); diff != "" {
t.Fatalf("different (-want +got):\n%s", diff)
}
}
}