| // 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() |
| 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: "path/to/file:test-contents:with-another-colon", |
| expected: &fileEdit{ |
| filepath: "path/to/file", |
| contents: "test-contents:with-another-colon", |
| }, |
| 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 error: %s", err) |
| } |
| if diff := cmp.Diff(test.expected, edit, cmp.AllowUnexported(fileEdit{})); diff != "" { |
| t.Fatalf("different (-want +got):\n%s", diff) |
| } |
| } |
| } |