#!/bin/sh

echo "Setting and getting attribute value from prepare-plug-foo hook"

# Read the initial value of 'target' attribute
if ! output=$(snapctl get :foo target); then
    echo "Expected snapctl get to be able to read the value of own 'target' attribute"
    exit 1
fi
expected_output="initialtarget"
if [ "$output" != "$expected_output" ]; then
    echo "Expected output to be '$expected_output', but it was '$output'"
    exit 1
fi

# Set own 'target' attribute.
if ! snapctl set :foo target=plugtarget; then
    echo "Expected snapctl set to be able to set the value of own 'target' attribute"
    exit 1
fi

# Read own 'target' attribute
if ! output=$(snapctl get :foo target); then
    echo "Expected snapctl get to be able to read the value of own 'target' attribute"
    exit 1
fi
expected_output="plugtarget"
if [ "$output" != "$expected_output" ]; then
    echo "Expected output to be '$expected_output', but it was '$output'"
    exit 1
fi

# Create (set) a completely new attribute
if ! snapctl set :foo newplugattribute=foo; then
    echo "Expected prepare-plug-foo hook to be able to create a new attribte"
fi
